/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.herenit.beijing.poc.empi;

import com.herenit.beijing.dh2011.business.empi.IPatientIndexManager;
import com.herenit.beijing.dh2011.business.ets.EtsServiceRemote;
import com.herenit.beijing.dh2011.entity.EtConcepts;
import com.herenit.beijing.dh2011.entity.PatientIndex;
import com.herenit.beijing.poc.empi.converter.TimeToDateConverter;
import com.herenit.beijing.poc.serverfactory.ServerFactory;
import java.awt.Component;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.naming.NamingException;
import javax.swing.*;
import org.jdesktop.beansbinding.*;
import org.jdesktop.beansbinding.Validator.Result;
import org.jdesktop.swingbinding.SwingBindings;
import org.jdesktop.swingx.JXDatePicker;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.ActionID;
import org.openide.awt.ActionReference;
import org.openide.util.Exceptions;
import org.openide.util.Lookup;
import org.openide.windows.TopComponent;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(dtd = "-//com.herenit.beijing.poc.empi//Empi//EN",
autostore = false)
@TopComponent.Description(preferredID = "EmpiTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE", 
persistenceType = TopComponent.PERSISTENCE_ALWAYS)
@TopComponent.Registration(mode = "editor", openAtStartup = false)
@ActionID(category = "Window", id = "com.herenit.beijing.poc.empi.EmpiTopComponent")
@ActionReference(path = "Menu/patientIndex", position = 332)
@TopComponent.OpenActionRegistration(displayName = "#CTL_EmpiAction",
preferredID = "EmpiTopComponent")
public final class EmpiTopComponent extends TopComponent {

    private PatientIndex patientIndex;
    private IPatientIndexManager patientIndexManager;
    private EtsServiceRemote etsService;
    private List<EtConcepts> sexList;
    private List<EtConcepts> marriageList;
    private List<EtConcepts> nationalityList;
    private List<EtConcepts> nationList;
    private List<EtConcepts> chargeTypeList;

    public void getService() throws NamingException {
//        ServerFactory serverFactory =
//                Lookup.getDefault().lookup(ServerFactory.class);
//        
//        System.out.println(serverFactory==null?"serverFactory is null!":serverFactory.getClass().getName());
//        patientIndexManager = (IPatientIndexManager) serverFactory.getServer(null, "java:global/com.herenit.dh2011_army.his_ejb_1.0/PatientIndexManager");
//        etsService = (EtsServiceRemote) serverFactory.getServer(null, "java:global/com.herenit.dh2011_army.his_ejb_1.0/EtsService");

        patientIndexManager = ServiceLookup.getDefault().lookup(IPatientIndexManager.class);
        etsService = ServiceLookup.getDefault().lookup(EtsServiceRemote.class);
    }

    public EmpiTopComponent() {
        try {
            getService();
        } catch (NamingException ex) {
            Exceptions.printStackTrace(ex);
        }
        patientIndex = new PatientIndex();

        initComponents();
        setName(org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "CTL_EmpiTopComponent"));
        setToolTipText(org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "HINT_EmpiTopComponent"));

        sexList = etsService.findByVersionId(6l);
        marriageList = etsService.findByVersionId(2l);
        nationList = etsService.findByVersionId(5l);
        nationalityList = etsService.findByVersionId(7l);
        chargeTypeList = etsService.findByVersionId(33l);

        sexCB.setRenderer(new EtConceptsRenderer());
        marriageCB.setRenderer(new EtConceptsRenderer());
        nationCB.setRenderer(new EtConceptsRenderer());
        nationalityCB.setRenderer(new EtConceptsRenderer());
        chargeTypeCB.setRenderer(new EtConceptsRenderer());

        BindingGroup bindingGroup1 = new BindingGroup();
        BindingGroup bindingGroup2 = new BindingGroup();

        Binding binding21 = SwingBindings.createJComboBoxBinding(AutoBinding.UpdateStrategy.READ_WRITE, sexList, sexCB);
        Binding binding31 = SwingBindings.createJComboBoxBinding(AutoBinding.UpdateStrategy.READ_WRITE, marriageList, marriageCB);
        Binding binding51 = SwingBindings.createJComboBoxBinding(AutoBinding.UpdateStrategy.READ_WRITE, nationList, nationCB);
        Binding binding61 = SwingBindings.createJComboBoxBinding(AutoBinding.UpdateStrategy.READ_WRITE, nationalityList, nationalityCB);
        Binding binding13 = SwingBindings.createJComboBoxBinding(AutoBinding.UpdateStrategy.READ_WRITE, chargeTypeList, chargeTypeCB);


        Binding binding0 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${patientId}"), patientIdText, BeanProperty.create("text"));
        binding0.setValidator(new Validator< String>() {

            @Override
            public Result validate(String t) {
                if (t == null || "".equals(t.trim())) {

                    System.out.println("患者标识号不能为空！");
                    return new Result(null, "患者标识号不能为空！");

                }
                return null;
            }
        });


        Binding binding1 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${name}"), nameText, BeanProperty.create("text"));
        Binding binding2 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${sex}"), sexCB, BeanProperty.create("selectedItem"));
        Binding binding3 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${marriage}"), marriageCB, BeanProperty.create("selectedItem"));
        Binding binding4 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${birthday}"), jXDatePicker1, BeanProperty.create("date"));
        binding4.setConverter(new TimeToDateConverter());
        Binding binding5 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${nation}"), nationCB, BeanProperty.create("selectedItem"));
        Binding binding6 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${nationality}"), nationalityCB, BeanProperty.create("selectedItem"));
        //        Binding binding7 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${identityId}"), jTextField4, BeanProperty.create("text"));
        Binding binding8 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${birthPlace}"), birthplaceText, BeanProperty.create("text"));
        Binding binding9 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${email}"), emailText, BeanProperty.create("text"));
        Binding binding10 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${homeAddress}"), homeAddressText, BeanProperty.create("text"));
        Binding binding11 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${telephone}"), telephoneText, BeanProperty.create("text"));
        Binding binding12 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${chargeType}"), chargeTypeCB, BeanProperty.create("selectedItem"));

        Binding binding15 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${contactName}"), contactNameText, BeanProperty.create("text"));
        Binding binding16 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${contactTelephoneText}"), contactTelephoneText, BeanProperty.create("text"));

        Binding binding17 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${contactAddressText}"), contactAddressText, BeanProperty.create("text"));

        Binding binding18 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${photo}"), photoImageView, BeanProperty.create("image"));
        Binding binding19 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, patientIndex, ELProperty.create("${identityId}"), identityIdText, BeanProperty.create("text"));
        // binding18.setConverter(new ByteArrayToImageConverter());



        bindingGroup1.addBinding(binding0);
        bindingGroup1.addBinding(binding1);
        bindingGroup1.addBinding(binding2);
        bindingGroup1.addBinding(binding3);
        bindingGroup1.addBinding(binding4);
        bindingGroup1.addBinding(binding5);
        bindingGroup1.addBinding(binding6);

        bindingGroup1.addBinding(binding8);
        bindingGroup1.addBinding(binding9);
        bindingGroup1.addBinding(binding10);
        bindingGroup1.addBinding(binding11);
        bindingGroup1.addBinding(binding12);

        bindingGroup2.addBinding(binding21);
        bindingGroup2.addBinding(binding31);
        bindingGroup2.addBinding(binding51);
        bindingGroup2.addBinding(binding61);
        bindingGroup2.addBinding(binding13);

        bindingGroup1.bind();
        bindingGroup2.bind();
        // System.out.println(binding0.isBound());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        birthplaceText = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        sexCB = new javax.swing.JComboBox();
        homeAddressText = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        chargeTypeCB = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        telephoneText = new javax.swing.JTextField();
        clinicNo = new javax.swing.JTextField();
        contactAddressText = new javax.swing.JTextField();
        contactTelephoneText = new javax.swing.JTextField();
        contactNameText = new javax.swing.JTextField();
        relationshipCB = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        identityIdText = new javax.swing.JTextField();
        nationalityCB = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        emailText = new javax.swing.JTextField();
        marriageCB = new javax.swing.JComboBox();
        nationCB = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        patientIdText = new javax.swing.JTextField();
        nameText = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jXDatePicker1 = new org.jdesktop.swingx.JXDatePicker();
        photoImageView = new org.jdesktop.swingx.JXImageView();

        setPreferredSize(new java.awt.Dimension(1024, 768));

        birthplaceText.setText(org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.birthplaceText.text")); // NOI18N
        birthplaceText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                birthplaceTextActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel8, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel8.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel11, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel11.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel10, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel10.text")); // NOI18N

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "工人", "农民", "军人", "学生", "商人" }));

        org.openide.awt.Mnemonics.setLocalizedText(jLabel12, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel12.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel19, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel19.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel2.text")); // NOI18N

        jLabel1.setForeground(new java.awt.Color(0, 52, 255));
        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel1.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel17, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel17.text")); // NOI18N

        homeAddressText.setText(org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.homeAddressText.text")); // NOI18N
        homeAddressText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                homeAddressTextActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel16, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel16.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel13, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel13.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel14, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel14.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel35, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel35.text")); // NOI18N

        telephoneText.setText(org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.telephoneText.text")); // NOI18N
        telephoneText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                telephoneTextActionPerformed(evt);
            }
        });

        clinicNo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clinicNoActionPerformed(evt);
            }
        });

        contactAddressText.setText(org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.contactAddressText.text")); // NOI18N
        contactAddressText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contactAddressTextActionPerformed(evt);
            }
        });

        contactTelephoneText.setText(org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.contactTelephoneText.text")); // NOI18N
        contactTelephoneText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contactTelephoneTextActionPerformed(evt);
            }
        });

        contactNameText.setText(org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.contactNameText.text")); // NOI18N
        contactNameText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contactNameTextActionPerformed(evt);
            }
        });

        relationshipCB.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "亲戚", "朋友", "同事" }));

        org.openide.awt.Mnemonics.setLocalizedText(jLabel15, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel15.text")); // NOI18N

        identityIdText.setText(org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.identityIdText.text")); // NOI18N
        identityIdText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                identityIdTextActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel18, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel18.text")); // NOI18N

        emailText.setText(org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.emailText.text")); // NOI18N
        emailText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                emailTextActionPerformed(evt);
            }
        });

        nationCB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nationCBActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel5.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel3.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel7.text")); // NOI18N

        patientIdText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                patientIdTextActionPerformed(evt);
            }
        });

        nameText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nameTextActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel4.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel6.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jButton2, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jButton2.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jButton4, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jButton4.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jButton5, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jButton5.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jButton6, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jButton6.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel22, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jLabel22.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jButton3, org.openide.util.NbBundle.getMessage(EmpiTopComponent.class, "EmpiTopComponent.jButton3.text")); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout photoImageViewLayout = new javax.swing.GroupLayout(photoImageView);
        photoImageView.setLayout(photoImageViewLayout);
        photoImageViewLayout.setHorizontalGroup(
            photoImageViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 119, Short.MAX_VALUE)
        );
        photoImageViewLayout.setVerticalGroup(
            photoImageViewLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 135, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(159, 159, 159)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel22)
                                .addGap(18, 18, 18)
                                .addComponent(contactAddressText, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(18, 18, 18)
                                .addComponent(marriageCB, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(45, 45, 45)
                                .addComponent(jLabel14)
                                .addGap(18, 18, 18)
                                .addComponent(identityIdText, javax.swing.GroupLayout.PREFERRED_SIZE, 291, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 298, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel11)
                                            .addGap(44, 44, 44))
                                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                            .addComponent(jLabel15)
                                            .addGap(18, 18, 18)))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addGap(1, 1, 1)
                                            .addComponent(homeAddressText, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(18, 18, 18)
                                            .addComponent(jLabel16)
                                            .addGap(12, 12, 12)
                                            .addComponent(telephoneText, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(nationalityCB, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(42, 42, 42)
                                            .addComponent(jLabel12)
                                            .addGap(37, 37, 37)
                                            .addComponent(nationCB, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(18, 18, 18)
                                            .addComponent(jLabel13)
                                            .addGap(39, 39, 39)
                                            .addComponent(chargeTypeCB, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel17)
                                    .addGap(31, 31, 31)
                                    .addComponent(contactNameText, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(43, 43, 43)
                                    .addComponent(jLabel18)
                                    .addGap(4, 4, 4)
                                    .addComponent(relationshipCB, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(12, 12, 12)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel19)
                                        .addComponent(jLabel7))
                                    .addGap(12, 12, 12)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(contactTelephoneText, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addComponent(jLabel1)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel2)
                                        .addComponent(jLabel3))
                                    .addGap(5, 5, 5)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(patientIdText, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(nameText, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel6)
                                        .addComponent(jButton5))
                                    .addGap(3, 3, 3)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel35)
                                        .addComponent(jXDatePicker1, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGap(18, 18, 18)
                                    .addComponent(clinicNo, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel8)
                                            .addGap(31, 31, 31)
                                            .addComponent(birthplaceText, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(18, 18, 18)
                                            .addComponent(jLabel10))
                                        .addGroup(layout.createSequentialGroup()
                                            .addGap(401, 401, 401)
                                            .addComponent(jLabel4)))
                                    .addGap(12, 12, 12)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(sexCB, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(emailText, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(101, 101, 101)
                                .addComponent(jButton2))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addComponent(jButton6)
                                .addGap(44, 44, 44)
                                .addComponent(photoImageView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())))
            .addGroup(layout.createSequentialGroup()
                .addGap(273, 273, 273)
                .addComponent(jButton3)
                .addGap(139, 139, 139)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(68, 68, 68)
                .addComponent(jLabel1)
                .addGap(12, 12, 12)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(photoImageView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(patientIdText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton5)
                            .addComponent(jLabel35)
                            .addComponent(clinicNo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton6))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(nameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6)
                            .addComponent(jLabel4)
                            .addComponent(sexCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jXDatePicker1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(21, 21, 21)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(birthplaceText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(emailText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel10))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addComponent(jLabel8)))
                        .addGap(27, 27, 27)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(nationCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel12))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addComponent(jLabel13))
                            .addComponent(chargeTypeCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(nationalityCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel11)))
                        .addGap(19, 19, 19)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(homeAddressText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(telephoneText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(contactNameText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(relationshipCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(contactTelephoneText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(5, 5, 5)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel17)
                                    .addComponent(jLabel18)
                                    .addComponent(jLabel19))))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(contactAddressText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jLabel22)
                                    .addComponent(jLabel7)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel5)
                                    .addComponent(marriageCB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel14)
                                    .addComponent(identityIdText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton4)
                            .addComponent(jButton3))))
                .addContainerGap(267, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void birthplaceTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_birthplaceTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_birthplaceTextActionPerformed

    private void homeAddressTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_homeAddressTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_homeAddressTextActionPerformed

    private void telephoneTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_telephoneTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_telephoneTextActionPerformed

    private void clinicNoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clinicNoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_clinicNoActionPerformed

    private void contactAddressTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contactAddressTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_contactAddressTextActionPerformed

    private void contactTelephoneTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contactTelephoneTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_contactTelephoneTextActionPerformed

    private void contactNameTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contactNameTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_contactNameTextActionPerformed

    private void identityIdTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_identityIdTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_identityIdTextActionPerformed

    private void emailTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_emailTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_emailTextActionPerformed

    private void nationCBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nationCBActionPerformed

        JComboBox jc = (JComboBox) evt.getSource();
        System.out.println(jc.getSelectedItem());
        System.out.println(jc.getItemCount());


    }//GEN-LAST:event_nationCBActionPerformed

    private void patientIdTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_patientIdTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_patientIdTextActionPerformed

    private void nameTextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nameTextActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nameTextActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed

        System.out.println(patientIndex.getName());
        System.out.println(patientIndex.getId());
        System.out.println(patientIndex.getPatientId());

        patientIndexManager.newIndex(patientIndex);

    }//GEN-LAST:event_jButton3ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField birthplaceText;
    private javax.swing.JComboBox chargeTypeCB;
    private javax.swing.JTextField clinicNo;
    private javax.swing.JTextField contactAddressText;
    private javax.swing.JTextField contactNameText;
    private javax.swing.JTextField contactTelephoneText;
    private javax.swing.JTextField emailText;
    private javax.swing.JTextField homeAddressText;
    private javax.swing.JTextField identityIdText;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private org.jdesktop.swingx.JXDatePicker jXDatePicker1;
    private javax.swing.JComboBox marriageCB;
    private javax.swing.JTextField nameText;
    private javax.swing.JComboBox nationCB;
    private javax.swing.JComboBox nationalityCB;
    private javax.swing.JTextField patientIdText;
    private org.jdesktop.swingx.JXImageView photoImageView;
    private javax.swing.JComboBox relationshipCB;
    private javax.swing.JComboBox sexCB;
    private javax.swing.JTextField telephoneText;
    // End of variables declaration//GEN-END:variables

    @Override
    public void componentOpened() {
    }

    @Override
    public void componentClosed() {
        // TODO add custom code on component closing
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    void readProperties(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }

    public IPatientIndexManager getPatientIndexManager() {
        return patientIndexManager;
    }

    public void setPatientIndexManager(IPatientIndexManager patientIndexManager) {
        this.patientIndexManager = patientIndexManager;
    }

    public PatientIndex getPatientIndex() {
        return patientIndex;
    }

    public void setPatientIndex(PatientIndex patientIndex) {
        this.patientIndex = patientIndex;
    }
}
